from selenium import webdriver
# from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from time import sleep
from postion import options
from postion import service

url=r'https://www.baidu.com/'

driver = webdriver.Chrome(options=options, service=service)
driver.get(url)


# # id定位
# driver.find_element(By.ID,'kw').send_keys('哔哩哔哩')
# driver.find_element(By.ID,'su').click()
# sleep(3)
#
# # name定位
# driver.find_element(By.NAME,'wd').send_keys('搞笑视频')
# driver.find_element(By.ID,'su').click()
# sleep(3)

# # tag定位
# driver.find_elements(By.TAG_NAME,'input')[7].send_keys('blbl')
# driver.find_elements(By.TAG_NAME,'input')[8].click()
# sleep(3)
#
# # class定位
# driver.find_element(By.CLASS_NAME,'s_ipt').send_keys('音乐')
# driver.find_element(By.CLASS_NAME,'bg.s_btn').click()
# # driver.find_elements(By.CLASS_NAME,'bg')[2].click()
# sleep(3)

# xpath定位
'''
xpath基本语法
/       根路径
//      相对路径
*       所有标签
input   指定标签
[@id="kw"] 指定属性
'''
# 1）绝对路径 *
driver.find_element(By.XPATH,'/html/body/div[2]/div[1]/div[5]/div/div/form/span[1]/input').send_keys('a6')
driver.find_element(By.XPATH,'/html/body/div[2]/div[1]/div[5]/div/div/form/span[2]/input').click()
sleep(3)

# # 2)相对路径
# driver.find_element(By.XPATH,'//*[@id="kw"]').send_keys('a6')
# driver.find_element(By.XPATH,'//*[@id="su"]').click()
# sleep(3)

# 相对路径之指定标签
# driver.find_element(By.XPATH,'//input[@id="kw"]').send_keys('a6')
# driver.find_element(By.XPATH,'//input[@id="su"]').click()
# sleep(3)

# 相对路径之指定上层元素的路径 *
# driver.find_element(By.XPATH,'//from[@id="from"]/span/input[@id="kw"]').send_keys('a6')
# driver.find_element(By.XPATH,'//*[@id="su"]').click()
# sleep(3)

# #相对路径之指定多个属性
# driver.find_element(By.XPATH,'//*[@id="kw" and @name="wd"]').send_keys('a6')
# driver.find_element(By.XPATH,'//*[@id="su"]').click()
# sleep(3)

# css定位

# # id选择器
# driver.find_element(By.CSS_SELECTOR,'#kw').send_keys('a6')
# driver.find_element(By.CSS_SELECTOR,'#su').click()
# sleep(3)

#class选择器
# driver.find_element(By.CSS_SELECTOR,'.s_ipt').send_keys('a6')
# driver.find_element(By.CSS_SELECTOR,'.bg .s_btn ').click()
# sleep(3)

# # 使用其他属性
# driver.find_element(By.CSS_SELECTOR, '[name="wd"]').send_keys('a7')
# driver.find_element(By.CSS_SELECTOR, '.bg .s_btn').click()
# sleep(3)

# # 使用多个属性
# driver.find_element(By.CSS_SELECTOR, '[name="wd"]').send_keys('a8')
# driver.find_element(By.CSS_SELECTOR, '.bg .s_btn[type="submit"][value="百度一下"]').click()
# sleep(3)

# 使用层级
# driver.find_element(By.CSS_SELECTOR,'form[id="form"]>span>input[name="wd"]').send_keys('a9')
# driver.find_element(By.CSS_SELECTOR,'.bg .s_btn[type="submit"][value="百度一下"]').click()
# sleep(3)

#link定位
# driver.find_element(By.LINK_TEXT,'新闻').click()
# sleep(3)

# partial_link定位
driver.find_element(By.PARTIAL_LINK_TEXT,'新').click()
sleep(3)

# driver.quit()